

package com.maoshi.shop.distribution.platform.controller;

import com.maoshi.shop.common.config.Constant;
import com.maoshi.shop.common.util.Json;
import com.maoshi.shop.distribution.comment.model.DistributionBindSet;
import com.maoshi.shop.distribution.comment.service.DistributionBindSetService;
import com.maoshi.shop.security.platform.util.SecurityUtils;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 绑定设置
 * @author lgh on 2019/04/01.
 */
@RestController
@RequestMapping("/platform/distributionBindSet")
@AllArgsConstructor
public class DistributionBindSetController {

    private DistributionBindSetService distributionBindSetService;

	/**
	 * 获取信息(根据店铺)
	 */
	@GetMapping("/info")
	@PreAuthorize("@pms.hasPermission('platform:distributionBindSet:info')")
	public ResponseEntity<DistributionBindSet> info(){
		return ResponseEntity.ok(distributionBindSetService.getByShopId());
	}

	/**
	 * 修改
	 */
	@PutMapping
	@PreAuthorize("@pms.hasPermission('platform:distributionBindSet:update')")
	public ResponseEntity<Void> update(@RequestBody @Valid DistributionBindSet distributionBindSet){
		Long shopId = Constant.PLATFORM_SHOP_ID;

		distributionBindSet.setBindSceneJson(Json.toJsonString(distributionBindSet.getBindScene()));
		distributionBindSet.setRobJson(Json.toJsonString(distributionBindSet.getRob()));
		distributionBindSet.setShopId(shopId);
		distributionBindSet.setModifier(SecurityUtils.getSysUser().getUserId());
		distributionBindSetService.updateById(distributionBindSet);
		distributionBindSetService.removeCacheByShopId(shopId);
		return ResponseEntity.ok().build();
	}

//	/**
//	 * 分页获取
//	 */
//   @GetMapping("/page")
//  @PreAuthorize("@pms.hasPermission('platform:distributionBindSet:page')")
//	public ResponseEntity<IPage<DistributionBindSet>> page(DistributionBindSet distributionBindSet,PageParam<DistributionBindSet> page){
//		IPage<DistributionBindSet> list = distributionBindSetService.page(page,new LambdaQueryWrapper<DistributionBindSet>());
//		return ResponseEntity.ok(list);
//	}

//  /**
//	 * 获取信息
//	 */
//	@GetMapping("/info/{id}")
//	@PreAuthorize("@pms.hasPermission('platform:distributionBindSet:info')")
//	public ResponseEntity<DistributionBindSet> info(@PathVariable("id") Long id){
//		DistributionBindSet distributionBindSet = distributionBindSetService.getById(id);
//		return ResponseEntity.ok(distributionBindSet);
//	}

//	/**
//	 * 删除
//	 */
//	@DeleteMapping("/{id}")
//	@PreAuthorize("@pms.hasPermission('platform:distributionBindSet:delete')")
//	public ResponseEntity<Void> delete(/*@PathVariable Long id*/){
//		DistributionBindSet distributionBindSet = distributionBindSetService.getByShopId(Constant.PLATFORM_SHOP_ID);
//		distributionBindSetService.removeById(distributionBindSet.getBindId());
//		distributionBindSetService.removeCacheByShopId(Constant.PLATFORM_SHOP_ID);
//		return ResponseEntity.ok().build();
//	}
}
